package com.order;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

//@Component//一定要记得加上，要被spring管理起来
@Aspect//此案例是用来理解各个通知执行顺序的，一定要确保只有这个切面生效，以免干扰
public class AdviceOrderAspect {

    @Before("execution(* com.service.impl.UserServieImpl.add(int,int))")
    public void before() {
        System.out.println("before---");
    }

    @AfterReturning("execution(* com.service.impl.UserServieImpl.add(int,int))")
    public void afterReturning() {
        System.out.println("after returning---");
    }

    @After("execution(* com.service.impl.UserServieImpl.add(int,int))")
    public void after() {
        System.out.println("after---");
    }

    @Around("execution(* com.service.impl.UserServieImpl.add(int,int))")
    public Object around(ProceedingJoinPoint joinPoint) {


        Object result = null;
        try {
            System.out.println("around before---");
            result = joinPoint.proceed();
            System.out.println("around after---");

        } catch (Throwable e) {

            e.printStackTrace();
        }

        return result;
    }


    @AfterThrowing(value = "execution(* com.service.impl.UserServieImpl.add(int,int))", throwing = "ex")
    public void afterThrowing(RuntimeException ex) {
        System.out.println("throwing---");
    }

}
